class BancosController < ApplicationController
  #MODULE: Configuraciones

  # GET /bancos
  # GET /bancos.xml
  def index
  end

  # GET /bancos/1
  # GET /bancos/1.xml
  def show
    @banco = Banco.find(params[:id])
    
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @banco }
    end
  end

  # GET /bancos/new
  # GET /bancos/new.xml
  def new
    @banco = Banco.new
    
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @banco }
    end
  end

  # GET /bancos/1/edit
  def edit
    @banco = Banco.find(params[:id])
  end

  # POST /bancos
  # POST /bancos.xml
  def create
    @banco = Banco.new(params[:banco])
    
    respond_to do |format|
      if @banco.save
        flash[:notice] =  'Banco creada correctamente.'
        format.html { params[:oper].nil? ? redirect_to(@banco) : render(:text => "Ok")}
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @banco.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /bancos/1
  # PUT /bancos/1.xml
  def update
    @banco = Banco.find(params[:id])
    
    respond_to do |format|
      if @banco.update_attributes(params[:banco])
        flash[:notice] = 'Banco actualizado correctamente.'
        format.html { redirect_to(@banco) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @banco.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /bancos/1
  # DELETE /bancos/1.xml
  def destroy
    @banco = Banco.find(params[:id])
    @banco.destroy

    respond_to do |format|
      format.html { redirect_to(bancos_url) }
      format.xml  { head :ok }
    end
  end

  def datos #IGNORE
    #Parametros
    registros, count = find_by_params(params, :class => Banco)
    # Construct a hash from the ActiveRecord result
    return_data = Hash.new()
    return_data[:page] = params[:page]
    return_data[:total] = (count.to_f / params[:rows].to_i).ceil
    return_data[:records] = count

    return_data[:rows] = registros.collect{|u| {:id=>u.id,
        :cell=>[
          u.nombre
        ]}}

    # Convert the hash to a json object
    render :text=>return_data.to_json, :layout=>false
  end
  
end
